package com.nandi.emergencyinspection.api

import com.nandi.emergencyinspection.api.response.BaseResponse
import com.nandi.emergencyinspection.bean.*
import com.orhanobut.hawk.Hawk
import com.tbright.ktbaselibrary.extension.create
import kotlinx.coroutines.Deferred
import okhttp3.MultipartBody
import retrofit2.http.*

interface ApiServices {

    companion object {
        val instance: ApiServices by lazy {
            create(ApiServices::class.java)
        }
    }

    @GET("/rys/user/getToken")
    fun singlePoetryAsync(): Deferred<BaseResponse<String>>

    /**
     * 登录
     */
    @POST("auth/oauth/token")
    @Headers("Content-Type: application/x-www-form-urlencoded", "Accept:application/json")
    fun loginAsync(
        @Header("Authorization") token: String? = "Basic bGg6bGg=",
        @Query("grant_type") grant_type: String? = "password",
        @Header("grant_type") grant_typehe: String? = "password",
        @Header("isToken") isToken: String = "false",
        @Header("code") code: String,
        @Header("randomStr") randomStr: String,
        @Query("username") username: String,
        @Header("password") password: String,
        @Query("scope") scope: String = "server"
    ): Deferred<BaseResponse<String>>

    @GET("admin/user/{id}")
    fun getUserInfoAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Path("id") id: String
    ): Deferred<BaseResponse<UserInfoBean>>


    /**
     * 获取任务list
     */
    @GET("device/emergency_task/Security/page")
    fun getTaskListAsync(
        @Header("Authorization") token: String,
        @Query("current") current: Int,
        @Query("size") size: Int,
        @Query("state") state: Int?,
        @Query("name") taskName: String?
    ): Deferred<BaseResponse<TaskListBean?>>

    /**
     * 获取隐患点list
     */
    @GET("disaster/disaster_base_info/Security/page")
    fun getDisasterListAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Query("current") current: Int,
        @Query("size") size: Int
    ): Deferred<BaseResponse<DisasterBean?>>

    /**
     * 获取宏观现象
     */
    @GET("disaster/disaster_macro_measured_data/page")
    fun getMacroAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Query("current") current: Int = 1,
        @Query("size") size: Int = 10000
    ): Deferred<BaseResponse<MacroListBean?>>

    /**
     * 获取宏观现象上报list
     */
    @GET("disaster/disaster_macro_observe_record/page")
    fun getMacroInfoListAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Query("current") current: Int,
        @Query("size") size: Int,
        @Query("disasterId") disasterId: Int,
        @Query("createTime_begin") createTime_begin: String?,
        @Query("createTime_end") createTime_end: String?
    ): Deferred<BaseResponse<MacroInfoListBean?>>

    /**
     * 获取宏观现象字典
     */
    @GET("admin/dict/type/{type}")
    fun getMacroDictAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Path("type") id: String = "marco_info"
    ): Deferred<BaseResponse<MutableList<MacroDictBean>>>
    /**
     * 获取IMToken
     */
    @POST("/rys/user/getToken")
    fun getImTokenAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Body map: Map<String, String>
    ): Deferred<BaseResponse<String>>

//    /**
//     * 获取IMToken
//     */
//    @POST("/im/user/getToken")
//    fun getImTokenAsync(
//        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
//        @Body map: Map<String, String>
//    ): Deferred<BaseResponse<String>>

    /**
     * 上报宏观
     */
    @POST("disaster/disaster_macro_observe_record")
    fun postMacroAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Body macroPostBean: MacroPostBean
    ): Deferred<BaseResponse<String>>

    /**
     * 提交任务
     */
    @PUT("device/emergency_task")
    fun submitTaskAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Body submitTaskBean: SubmitTaskBean
    ): Deferred<BaseResponse<String?>>

    /**
     * 上传文件
     */
    @Multipart
    @POST("file/upload")
    fun uploadFile(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Part file: MultipartBody.Part
    ): Deferred<BaseResponse<FileBean>>

    /**
     * 接受任务
     */
    @PUT("device/emergency_task/updateStatus")
    fun acceptTaskAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Query("id") id: String,
        @Query("status") status: Int
    ): Deferred<BaseResponse<String?>>

    /**
     * 修改密码
     */
    @PUT("admin/user/edit")
    fun editInfoAsync(
        @Header("Authorization") authorization: String? = "bearer${Hawk.get<String>("TOKEN")}",
        @Body editUserBean: EditUserBean
    ): Deferred<BaseResponse<String?>>
}